<!--
 * @FilePath     : /study_code/vue/beforeCreate copy.html
 * @Description  : beforeDestroy, destroyed 钩子
 * @Date         : 2025-05-02 09:16:35
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-05-02 09:16:35
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div id="app" v-clock>
      <button @click="destruyHandle">销毁实例</button>
    </div>

    <script src="/vue/dist/vue.min.js"></script>
    <script src="./common.js"></script>
    <script>
      // 自定义组件
      const myComponent = {
        data: function () {
          return {}
        },
        props: [],
        template: ``,
        methods: {},
      }

      var app = new Vue({
        el: '#app',
        data: function () {
          return {
            count: 2,
          }
        },
        computed: {
          longCount() {
            return (this.count += 3)
          },
        },
        methods: {
          destruyHandle() {
            this.$destroy()
            console.log('实例已销毁')
          },
        },

        /**
         * @brief: 实例销毁之前调用。
         * ! 在这一步，实例仍然完全可用。
         * @return {*}
         */
        beforeDestroy() {
          console.log('----------------------------beforeDestroy')
          console.log(this) // 当前实例
        },

        /**
         * @brief: 例销毁后调用。该钩子被调用后
         * ！实例已销毁，this 不可用
         * @return {*}
         */
        destroyed() {
          console.log('----------------------------destroyed')
          console.log(this) // undefined
        },
      })
    </script>
  </body>
</html>
